<?php
/* @var $this TurmaController */
/* @var $model Turma */

$this->pageTitle=Yii::app()->name . ' - Visualizar Turma';

$this->breadcrumbs=array(
		'Turmas'=>array('index'),
		$model->nome,
);

$this->menu=array(
		array('label'=>'Matricular '.Aluno::getModuleName().'s', 'url'=>array('cadastrados', 'id'=>$model->id), 'visible'=>Yii::app()->session['idAtual'] == $model->responsavel_id && Yii::app()->session['polo_id'] != '1' && $model->ano >= date('Y')),
		array('label'=>'Frequências', 'url'=>array('/frequencia', 'id'=>$model->id),'visible'=>Yii::app()->session['idAtual'] == $model->responsavel_id),
		array('label'=>'Plano de Curso', 'url'=>array('plano', 'id'=>$model->id)),
		array('label'=>'Cadastrar Aula','url'=>array('/aula/create', 'id'=>$model->id), 'visible'=>Yii::app()->session['idAtual'] == $model->responsavel_id && $model->ano >= date('Y')),
		array('label'=>'Alterar Esta Turma', 'url'=>array('update', 'id'=>$model->id),'visible'=>Yii::app()->session['idAtual'] == $model->responsavel_id || $model->responsavel_id == 0 || Yii::app()->session['idAtual'] == 1),
		array('label'=>'Deletar Esta Turma', 'url'=>'#', 'linkOptions'=>array('submit'=>array('delete','id'=>$model->id),'confirm'=>'Deseja realmente deletar esta Turma?'), 'visible' =>Yii::app()->session['idAtual'] == $model->responsavel_id && $model->ano >= date('Y')),
		array('label'=>'Criar Nova Turma', 'url'=>array('create')),
		array('label'=>'Gerenciar Turmas', 'url'=>array('admin')),
);
?>
<legend>
	<h3 align="center">
		<?php 
		echo $model->nome;
		?>		
	</h3>
	<?php
	if($model->ano < date('Y')) {
		echo '<h4 align="right" style="color:#777777"> (Fechada)</h4>';
	}
	?>
</legend>
<div class="row" style="margin-bottom: 40px; margin-top: 40px;">
	<div class="column" style="margin-right: 20px; min-width: 360px; max-width: 360px;">
		<p class="title" align="center" style="font: italic;">DETALHES DA
			TURMA</p>

		<?php $this->widget('bootstrap.widgets.TbDetailView',array(
				'cssFile' => Yii::app()->baseUrl .'/css/detail.css',
				'data'=>$model,
				'attributes'=>array(
					 array(
					 		'name'=>'id', // only admin user can see person id
					 		'visible'=>Yii::app()->user->name=='admin'? true : false,
					 ),
						'nome',
						'classe.nome',
						'ano',
						'vagas',
						array(
								'name' =>'responsavel_id',
								'value'=>$model->responsavel == null ? '' : $model->responsavel->pessoa->nome,
						),
							
				),
		));

		?>
	</div>

	<div class="column" style="min-width: 350px; max-width: 350px;">

		<p class="title" align="center"
			style="font: italic; text-transform: uppercase; margin-bottom: 13px;">
			<?php echo Aluno::getModuleName().'s Matriculados';?>
		</p>
		<?php 
		$condition = array();
		if( Yii::app() -> session['polo_id'] == 1) {
			$condition = array('turma_int' => $model->id);
		} else {
			$condition = array('turma_int'=>$model->id);
		}
		?>
		<?php $alunosId = TurmaHasAluno::model()->findAllByAttributes($condition);?>
		<?php 
		$position = 0;
		foreach($alunosId as $id) {
			$background = '#000000';
			$adicional = '';
			if($id->status != 'Ativo' && Yii::app() -> session['polo_id'] == 1) {
				$background= '#888888';
				$adicional = ' ('.$id->status.')';
			}
			$aluno = Aluno::model()->findByAttributes(array('id'=>$id->aluno_id));
			$pessoa = Pessoa::model()->findByAttributes(array('id'=>$aluno->pessoa_id));
			$color = $position % 2 != 0 ? "#C4E9E3;" : "#F3F9F8";
			echo '<p align="center" style="background:'.$color.'; padding:3px; margin-bottom:0px;">';
			echo CHtml::link('<b style="color:'.$background.'">'.$pessoa->nome. $adicional.'</b>',
					Yii::app()->request->baseUrl ."/index.php?r=turmaHasAluno/view&id=".$id->id, 
					array('class' => 'meulink'));
			echo "</p>";
			$position ++;
		}
		?>
	</div>
</div>
<div class="row">
	<legend>
		<h4 align="right">
			Aulas da Turma
			</h3>
	
	</legend>
	<?php 
	
	//verificação para não permitir que usuários apaguem dados que não os pertencem
	
	$template = '{view}';
	if(Yii::app()->session['idAtual'] == $model->responsavel_id && $model->ano >= date('Y')) {
		$template = '{view} {update} {delete}';
	}
	
	
	$aula = new Aula('search');
	$this->widget('bootstrap.widgets.TbGridView',array(
			'id'=>'aula-grid',
			'pager' => array('cssFile' => Yii::app()->baseUrl . '/css/gridview.css',
					'firstPageLabel'=>'Início',
					'lastPageLabel'=>'Fim',
					'nextPageLabel'=>'Próximo >',
					'header'=>'Página Atual:',
					'prevPageLabel'=>'< Anterior',
					'maxButtonCount'=>'15',),
			'cssFile' => Yii::app()->baseUrl . '/css/gridview.css',
			'htmlOptions'=>array('class'=>'grid-view rounded'),
			'summaryText' => 'Mostrando {start}-{end} de {count} registro(s).',
			'dataProvider'=>$aula->search($model->id),
			'columns'=>array(
					'numero',
					'local',
					'horario',
					'data',
					array(
							'header' => 'Ações',
							'class' => 'CButtonColumn',
							'htmlOptions' =>array('width'=>'60px'),
							'viewButtonImageUrl' => Yii::app()->baseUrl . '/css/' . 'gr-view.png',
							'updateButtonImageUrl' => Yii::app()->baseUrl . '/css/' . 'gr-update.png',
							'deleteButtonImageUrl' => Yii::app()->baseUrl . '/css/' . 'gr-delete.png',
							'template' => $template,
							'deleteConfirmation'=>"js:'Deseja Realmente excluir esta Aula?'",
							'buttons'=>array (
									'view' => array (
											'class'=>'view',
											'label' => 'Visualizar Aula',
											'url'=>'Yii::app()->createUrl("/aula/view", array("id"=>$data->id))',
									),
									'update' => array
									(
											'class'=>'update',
											'label'=>'Editar Aula',
											'url'=>'Yii::app()->createUrl("/aula/update", array("id"=>$data->id))',
									),
									'delete' => array
									(
											'class'=>'delete',
											'label'=>'Deletar Aula',
											'url'=>'Yii::app()->createUrl("/aula/delete", array("id"=>$data->id))',
											'confirm'=>'Deseja realmente deletar esta Aula?'
									),
							),
					),


			), 'emptyText' => 'Nenhuma Aula cadastrada',
	));
	?>
</div>
<br />
<br />
